﻿using CloudFranceTriple.Models;
using CloudFranceTriple.WebRole.Filters;
using System.Collections.Generic;
using System.Linq;

namespace CloudFranceTriple.WebRole
{
    public class RoleConfig
    {
        /// <summary>
        /// Ajouter ici les nouveaux roles créés par défaut.
        /// </summary>
        public static void RegisterRoles()
        {
            //
            // Roles.MaxCachedResults, défini dans le Web.Config, est à mettre à jour en fonction du nombre de role créé ici
            //

            var AppRoles = new List<string> { "RoleFans", "RoleBaffMember", "RoleBaffGuildMaster", "RolePublic",
                                           "RoleAdminForum","RoleAdminWebApp","RoleDevWebApp","RoleHR",
                                           "RoleMember","RoleAdminShoutBox","RoleAdminGaming","RoleAdminGame",
                                           "RoleAdminSettings","RoleAdminNews","RoleAdminAnnonce","RoleAdminEvent",
                                           "RoleAdminLaBaff","RoleAdminAccount","RoleReaderAccount","RoleAuthorPollOnPortail","RoleUnitTest","RoleUnitTest2",
                                           "RollVeteranWall"};

            using (var db = new cloudfrAboq2RsDMEntities())
            {
                foreach (string thisRole in AppRoles)
                {
                    if (db.webpages_Roles.Where(r => r.RoleName == thisRole).Count() == 0)
                    {
                        db.webpages_Roles.Add(new webpages_Roles { RoleName = thisRole });
                    }
                }
                db.SaveChanges();
            }
        }
    }
}
